package com.ruoyi.admin.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.admin.domain.Hospital;
import com.ruoyi.admin.service.IHospitalService;
import com.ruoyi.admin.vo.DepartmentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.admin.domain.Department;
import com.ruoyi.admin.service.IDepartmentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 科室信息Controller
 *
 * @author ruoyi
 * @date 2022-10-23
 */
@RestController
@RequestMapping("/department")
public class DepartmentController extends BaseController
{
    @Autowired
    private IDepartmentService departmentService;
    @Autowired
    private IHospitalService hospitalService;
    /**
     * 查询科室信息列表
     */
    @RequiresPermissions("admin:department:list")
    @GetMapping("/list")
    public TableDataInfo list(Department department)
    {
        startPage();
        List<DepartmentVO> list = departmentService.showAllDepartment(department);
        return getDataTable(list);
    }

    /**
     * 导出科室信息列表
     */
    @RequiresPermissions("admin:department:export")
    @Log(title = "科室信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Department department)
    {
        List<Department> list = departmentService.selectDepartmentList(department);
        ExcelUtil<Department> util = new ExcelUtil<Department>(Department.class);
        util.exportExcel(response, list, "科室信息数据");
    }

    /**
     * 获取科室信息详细信息
     */
    @RequiresPermissions("admin:department:query")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(departmentService.selectDepartmentByDeptId(deptId));
    }

    /**
     * 新增科室信息
     */
    @RequiresPermissions("admin:department:add")
    @Log(title = "科室信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Department department)
    {
        return toAjax(departmentService.insertDepartment(department));
    }


    /**
     * 修改科室信息
     */
    @RequiresPermissions("admin:department:edit")
    @Log(title = "科室信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Department department)
    {
        return toAjax(departmentService.updateDepartment(department));
    }





    /**
     * 删除科室信息
     */
    @RequiresPermissions("admin:department:remove")
    @Log(title = "科室信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(departmentService.deleteDepartmentByDeptIds(deptIds));
    }
}